package com.zhj.product.controller;

import com.zhj.product.entity.dto.CategoryDTO;
import com.zhj.product.entity.dto.GoodItemsDTO;
import com.zhj.product.entity.pojo.Carousel;
import com.zhj.product.entity.pojo.Category;
import com.zhj.product.service.CarouselService;
import com.zhj.product.service.CategoryService;
import com.zhj.product.service.ItemsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/index")
@Api(tags = "轮播图接口")
public class ProductController {

    @Resource
    private CarouselService carouselService;

    @Resource
    private CategoryService categoryService;

    @Resource
    private ItemsService itemsService;

    /**
     * 查询首页的轮播图
     * @return
     */
    @GetMapping("/carousel")
    @ApiOperation(("查询所有轮播图"))
    public List<Carousel> selectAll() {
        return carouselService.findAll(1);
    }

    /**
     * 查询所有大类
     * @return
     */
    @GetMapping("/cats")
    @ApiOperation(("查询所有大分类"))
    public List<Category> selectCats() {
        return categoryService.selectCategoryRoot();
    }

    @GetMapping("/subCat/{fatherId}")
    @ApiOperation(("查询分类下面所有的子类"))
    public List<CategoryDTO> selectSubCat(@PathVariable("fatherId") Integer fatherId) {
        return categoryService.selectCategoryChildren(fatherId);
    }


    @GetMapping("/sixNewItems/{categoryId}")
    @ApiOperation(("查询首页好物推荐"))
    public List<GoodItemsDTO> selectGoodItems(@PathVariable("categoryId") Integer categoryId) {
        return itemsService.selectGoodItems(categoryId);
    }



}
